package util;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUill {
    private static SessionFactory sf;
    private HibernateUill() {}
    static {//读配置文件
        Configuration cf=new Configuration().configure();
        sf=cf.buildSessionFactory();//实例化对象
    }
    //产生会话
    public static Session getSession(){
        return sf.getCurrentSession();//当前无Session时创建一个，无需关闭
    }
}
